#ifndef _NONOS_H_
#define _NONOS_H_

#include <stdbool.h>
#include <stdint.h>

#ifndef __cplusplus
#ifndef nullptr
#define nullptr (void*)(0)
#endif
#endif /* __cplusplus */

#define NOS_TASK_NUM_MAX 10

typedef uint32_t               nos_evmap_t;
typedef struct nos_task_tcb_t* nos_task_t;
typedef void (*nos_timer_func_t)(void* args);
typedef void (*nos_event_func_t)(nos_evmap_t events, void* args);

/**
 * @brief create a event task
 *
 * @param task_func a simple function (never be block)
 * @param task_args
 * @param events
 * @return nos_task_t
 */
nos_task_t nos_event_task_create(nos_event_func_t task_func, void* task_args, nos_evmap_t events);

/**
 * @brief create a event task
 *
 * @param task_func a simple function (never be block)
 * @param task_args
 * @param period
 * @param delay period offset
 * @return nos_task_t
 */
nos_task_t nos_timer_task_create(nos_timer_func_t task_func, void* task_args, uint32_t period, uint32_t delay);

/**
 * @brief delete a task
 * 
 * @param task 
 */
void nos_task_delete(nos_task_t task);

/**
 * @brief post an event to task
 *
 * @param task
 * @param event
 * @return int
 */
int nos_event_post(nos_task_t task, nos_evmap_t event);

/**
 * @brief called in a loop by user
 *
 * @return int
 */
int nos_main();

/**
 * @brief called in systick by user
 *
 */
void nos_systick(void);

/**
 * @brief get timestamp
 *
 */
uint32_t nos_timestamp(void);

/**
 * @brief implement by user
 *
 * @return int
 */
extern int nos_user_init(void);

#endif
